﻿package bdz.common.effects
{
	import bdz.common.events.GenericEvent;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.utils.*;
	/**
	 * ...
	 * @author ...
	 */
	internal class StringRandomizer extends EventDispatcher {
		private var count:int;
		private var current:int;
		private var enterFramer:Shape;
		public var reference:int;
		private var end:String;
		private var inter:Number;
		function StringRandomizer(len:Number, e:String, sp:Number) {
			enterFramer = new Shape();
			count = len;
			end = e;
			current = 0;
			inter = setInterval(generate, sp);
		}
		private function generate():void {
			if (current < count) {
				dispatchEvent(new GenericEvent(GenericEvent.CHANGE, getRandomString()));
				current++;
			}else {
				clearInterval(inter);
				dispatchEvent(new GenericEvent(GenericEvent.COMPLETE, end));
			}
		}
		public function getRandomString():String {
			return String.fromCharCode(Math.random() * 60 + 64);
		}
	}
	
}